
/*
*
*/

#pragma once

#include "CxType.h"
#include <string>
#include <vector>
using std::vector;
using std::string;

BEGIN_NAMESPACE(MSG_SIGN)

typedef	unsigned int  CommandID;


const CommandID  CID_settime		= 1 ;
const CommandID  CID_readtime		= 2 ;
const CommandID  CID_markimg		= 3 ;
const CommandID  CID_sendimg		= 4 ;
const CommandID  CID_sendprolist	= 5 ;
const CommandID  CID_string			= 6 ;
const CommandID  CID_line			= 7 ;
const CommandID  CID_switchscene	= 8 ;
const CommandID  CID_copyscene		= 9 ;
const CommandID  CID_clearscene		= 10 ;
const CommandID  CID_setzh			= 11 ;
const CommandID  CID_light			= 12 ;
const CommandID  CID_settemper		= 13 ;
const CommandID  CID_settempershift = 14 ;
const CommandID  CID_setrelyswitch	= 15 ;
const CommandID  CID_losepointon	= 16 ;
const CommandID  CID_readlosepoint	= 17 ;
const CommandID  CID_readpower		= 18 ;
const CommandID  CID_readblind		= 19 ;
const CommandID  CID_clearpower		= 20 ;
const CommandID  CID_readworkstate	= 21 ;
const CommandID  CID_setprolist		= 22 ;
const CommandID  CID_setautotime	= 23 ;


//the abstruct transaction class
class CxTransaction
{
protected:
	// common define
	typedef unsigned		char	byte;
	typedef unsigned		char*	bytes;
	typedef vector<byte>	_Data;

public:

	//fatory method 
	static		CxTransaction * __stdcall create(CommandID  ,const _Data &data);

public:
	virtual		~CxTransaction(){}
	
	virtual		bool			isNull()const=0;

	virtual		size_t			getid()const=0;
	virtual		vector<byte>	get()const=0;
};

//NULL  command
class CxNullCommand  : public CxTransaction
{
public:
	~CxNullCommand(){}
	size_t			getid()const{return 0;}
	vector<byte>	get()const{return vector<byte>();}

	bool			isNull()const{return true;}
};



//Time command
class CxTimeCommand : public CxTransaction 
{
public:
	CxTimeCommand(_Data d):data(d){}
	~CxTimeCommand(){}

	size_t			getid()const{return CID_settime;}
	vector<byte>	get()const
	{
		string str("Time Command");
		return vector<byte>(str.begin(),str.end());
	}
	bool			isNull()const{return false;}
private:
	_Data			data;
};


CxTransaction *CxTransaction::create(CommandID  id,const _Data &data)
{
	switch(id)
	{
	case CID_settime:
		return new CxTimeCommand(data);
		break;
	default:
		return  new CxNullCommand;
		break;
	}
}


END_NAMESPACE 


